﻿// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : tian_
// Created          : 12-03-2019
//
// Last Modified By : tian_
// Last Modified On : 12-03-2019
// ***********************************************************************
// <copyright file="ModelFileBinaryDbUtil.cs" company="北京智帆高科科技有限公司">
//     Copyright © 北京智帆高科科技有限公司 2018
// </copyright>
// <summary></summary>
// ***********************************************************************

using System.Collections.Generic;
using OSS.BIM.Model;
using ZFGK.Utility;

namespace OSS.BIM.Business.Utility
{
    /// <summary>
    /// Class ModelFileBinaryDbUtil.
    /// </summary>
    public static class ModelFileBinaryDbUtil
    {
        /// <summary>
        /// News the identifier if not set.
        /// </summary>
        /// <param name="modelFileBinary">The model file binary.</param>
        public static void NewIdIfNotSet(this ModelFileBinary modelFileBinary)
        {
            if (modelFileBinary.ModelFileBinaryId == 0)
                modelFileBinary.ModelFileBinaryId = SnowflakeUtil.GetId();
        }
        /// <summary>
        /// Inserts the specified model property.
        /// </summary>
        /// <param name="modelProperty">The model property.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool Insert(ModelFileBinary modelProperty)
        {
            modelProperty.NewIdIfNotSet();// 赋予唯一ID
            return DB.Context.Insert(modelProperty) > 0;
        }

        /// <summary>
        /// Inserts the specified model propertys.
        /// </summary>
        /// <param name="modelFileBinaries">The model propertys.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool Insert(IEnumerable<ModelFileBinary> modelFileBinaries)
        {
            modelFileBinaries.ForEach(d => d.NewIdIfNotSet());// 赋予唯一ID
            return DB.Context.Insert(modelFileBinaries) > 0;
        }
    }
}
